package com.hmall.search.web;

import com.hmall.common.dto.PageDTO;
import com.hmall.search.pojo.ItemDOC;
import com.hmall.search.pojo.ItemSearch;
import com.hmall.search.service.SearchService;
import org.elasticsearch.action.search.SearchRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/search")
public class SearchController {
    @Autowired
    SearchService searchService;
    /**
     * 搜索自动补全
     * @param key
     * @return
     */
    @GetMapping("/suggestion")
    public List<String> suggestion(String key){
        return searchService.search(key);
    }
    
    /**
     * 搜索分页查询
     * @return
     */
    @PostMapping("/list")
    public PageDTO<ItemDOC> list(@RequestBody ItemSearch itemSearch){
        return searchService.list(itemSearch);
    }
    
    /**
     * 根据过滤条件聚合查询
     * @param itemSearch
     * @return
     */
    @PostMapping("/filters")
    public Map<String,List<String>> filter(@RequestBody ItemSearch itemSearch){
        return searchService.filter(itemSearch);
    }
}
